package cohesion.system.trigger
{

	/**
	 * <dl>
	 *
	 * 	<dt>文件描述:</dt>
	 *		<dd>每个触发器中“帧回调方法”数据值对象，该类为包内封闭类，仅在TriggerTimer中被调用</dd>
	 *
	 *	<dt>创建日期:</dt>
	 *		<dd>2012-2-21</dd>
	 *
	 * 	<dt>更新日期:</dt>
	 *		<dd>2012-2-21</dd>
	 *
	 * 	<dt>文件版本:</dt>
	 *		<dd>1.0</dd>
	 *
	 * </dl>
	 *
	 * @author ZQiang张强
	 */
	internal class TriggerVO
	{
		private var delay:int;
		private var counter:int;
		private var repeat:int;
		internal var onUpdate:Function;
		private var onUpdateParams:Array;
		private var onComplete:Function;
		private var onCompleteParams:Array;

		public function TriggerVO($delay:int , $repeat:int , $onUpdate:Function , $onUpdateParams:Array = null , $onComplete:Function = null , $onCompleteParams:Array = null)
		{
			delay = $delay;
			counter = delay;
			repeat = $repeat;
			onUpdate = $onUpdate;
			onUpdateParams = $onUpdateParams;
			onComplete = $onComplete;
			onCompleteParams = $onCompleteParams;
		}

		internal function release():void
		{
			onUpdate = null;
			onUpdateParams = null;
			onComplete = null;
			onCompleteParams = null;
		}

		internal function trigger():Boolean
		{
			if (--counter <= 0)
			{
				counter = delay;
				doRepeat();
				if (repeat > 0 && --repeat == 0)
				{
					doFinish();
					return true;
				}
			}
			return false;
		}

		private function doRepeat():void
		{
			onUpdate.apply(null , onUpdateParams);
		}

		private function doFinish():void
		{
			if (onComplete != null)
				onComplete.apply(null , onCompleteParams);
		}
	}
}